package com.example.base.mvvm

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

abstract class BaseActivity<VDB:ViewDataBinding,VM:ViewModel>:AppCompatActivity() {
    //定义binding和viewModel //延迟初始化
    lateinit var binding:VDB
    lateinit var viewModel:VM
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this,getLayout())
        viewModel = ViewModelProvider(this)[getViewModel()]
        initView()
        initData()
    }

    abstract fun initView()

    abstract fun initData()

    abstract fun getViewModel(): Class<VM>

    abstract fun getLayout():Int

    /**
     * 页面销毁
     */
  /*  override fun onDestroy() {
        super.onDestroy()
        if(binding!=null){
            binding = null
        }
    }*/
}